<template>
	<view>
		<uni-table border stripe type="selection" emptyText="暂无更多数据" @selection-change="selectionChange">
			<uni-tr>
				<uni-th align="center">序号</uni-th>
				<uni-th align="center">不良编码</uni-th>
				<uni-th align="center">不良名称</uni-th>
				<uni-th align="center">不良类型</uni-th>
				<uni-th align="center">适用类别</uni-th>
			</uni-tr>
			<uni-tr v-for="(item,i) in  badCodeShowList" :key="i">
				<uni-td align="center">{{i+1}}</uni-td>
				<uni-td align="center">{{item.ug002}}</uni-td>
				<uni-td align="center">{{item.ug003}}</uni-td>
				<uni-td align="center">{{item.ug005}}</uni-td>
				<uni-td align="center">{{item.ug006}}</uni-td>
			</uni-tr>
		</uni-table>
		<view class="flowBefore-actions">
			<u-button class="buttom-btn" type="primary" @click.stop="handleConfirm">
				提交
			</u-button>
		</view>
	</view>
</template>

<script>
	import request from "@/utils/request";
	export default {
		data() {
			return {
				badCodeShowList: [],
				indexList: []
			}
		},
		onLoad(option) {

		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				let query = {
					currentPage: 1,
					pageSize: 100,
					sort: 'asc',
					sidx: null
				}
				request({
					url: `/api/SubDev/Copug/BadCodeList`,
					method: "get",
					data: query,
				}).then((res) => {
					this.badCodeShowList = res.data.list
				})
			},
			// 多选
			selectionChange(e) {
				this.indexList = e.detail.index
				console.log(this.indexList)
			},
			//确 认
			handleConfirm() {
				const selectedObjects = this.indexList.map(index => this.badCodeShowList[index]).map(item => {
					return {
						uh007: item.ug001, //不良id
						uh008: item.ug003, //不良名称
						uh009: 1 //不良次数
					}
				});
				let list = selectedObjects
				uni.$emit('upbadCodeList', selectedObjects)
				setTimeout(() => {
					uni.navigateBack()
				}, 300)
			},
		}
	}
</script>